package com.ruoyi.demo.controller;


import com.alibaba.fastjson.JSON;
import com.ruoyi.demo.config.ElasticSearchConfiguration;
import com.ruoyi.demo.domain.House;
import com.ruoyi.demo.service.HouseService;
import com.ruoyi.demo.util.EsUtil;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RequestMapping("es")
@CrossOrigin
@RestController
public class EsController {


    @Autowired
    private ElasticSearchConfiguration elasticsearchConfig;


    @Autowired
    HouseService houseService;


    @RequestMapping("list")
    @ResponseBody
    private void init() {
        List<House> list = houseService.list();

        EsUtil.insetBach("wei", list);
     /*   EsUtil.insertData("wei","id_"+System.currentTimeMillis(), JSON.toJSONString(list.get(0)));*/

      /*  List<House> wei = EsUtil.searchData("wei", new SearchSourceBuilder(), null, House.class);
        System.out.println(wei.toString());
        return wei;*/
    }
}
